import java.util.Comparator;
import java.util.PriorityQueue;

public class Test2 implements Comparable<Test2> {
    public int age;
    public String name;

    public Test2(int age, String name) {
        this.age = age;
        this.name = name;
    }

    public Test2() {

    }

    @Override
    public String toString() {
        return "Test2{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public int compareTo(Test2 o) {
        return this.age-o.age;
    }

    class NameComparator implements Comparator<Test2> {//比较器
        @Override
        public int compare(Test2 o1, Test2 o2) {
            return o1.name.compareTo(o2.name);
        }
    }
    public static void main(String[] args) {
        Test2 test2=new Test2(55,"w");
        Test2 test=new Test2(18,"wd");

        System.out.println(test.compareTo(test2));

        PriorityQueue<Test2> priorityQueue=new PriorityQueue<>(new Test2().new NameComparator());
        priorityQueue.offer(test);

        Test2.NameComparator nameComparator=new Test2(14,"dfwer").new NameComparator();

        System.out.println(nameComparator.compare(test, test2));
    }
}
